<?php

namespace Wcent\Controller;

#use Think\Controller;

class IndexController extends CommController
{
    public function index()
    {
        $pass = M("pass");
        $where["ps_openid"] = $this->openid;
        $info = $pass->where($where)->find();
        if ($info["ps_phone"] != null) {
            session("cdk", $info["ps_phone"]);
            $this->redirect("Ucent/index");
        }
        $this->assign("wxname", $this->wexinfo["nickname"]);
        $this->display();
    }

    public function doWechaToBin()
    {
        $pass = M("pass");
        
        $data = $pass->create();
        if (!$data) {
            $this->redirect("Index/index");
        }
        $data['ps_pass'] = encodepass($data['ps_pass']);
        $info = $pass->where($data)->find();
        if ($info["ps_phone"] == null) {
            $this->redirect("Index/index");
        }
        if ($pass->where($data)->save(array("ps_openid" => $this->openid))) {
            session("cdk", $data["ps_phone"]);
            $this->redirect("Ucent/index");
        }
        $this->redirect("Index/index");
    }
}
